package com.cherry.androidviewdemo.activity

import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentPagerAdapter
import android.support.v7.app.AppCompatActivity
import com.cherry.androidviewdemo.R
import com.cherry.androidviewdemo.bean.PageModel
import com.cherry.androidviewdemo.fragment.PageFragment
import kotlinx.android.synthetic.main.tab_viewpager.*

/**
 * @author DongMS
 * @since 2020/5/20
 */
class DrawOrderActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.tab_viewpager)
        val pageModels = arrayListOf(
                PageModel(R.layout.sample_after_on_draw, R.string.title_after_on_draw),
                PageModel(R.layout.sample_before_on_draw, R.string.title_before_on_draw)
//                PageModel(R.layout.sample_on_draw_layout, R.string.title_on_draw_layout),
//                PageModel(R.layout.sample_dispatch_draw, R.string.title_dispatch_draw),
//                PageModel(R.layout.sample_after_on_draw_foreground, R.string.title_after_on_draw_foreground),
//                PageModel(R.layout.sample_before_on_draw_foreground, R.string.title_before_on_draw_foreground),
//                PageModel(R.layout.sample_after_draw, R.string.title_after_draw),
//                PageModel(R.layout.sample_before_draw, R.string.title_before_draw)
        )

        pager.adapter = object : FragmentPagerAdapter(supportFragmentManager) {

            override fun getItem(position: Int): Fragment {
                val pageModel = pageModels[position]
                return PageFragment.newInstance(pageModel.sampleLayoutRes)
            }

            override fun getCount(): Int {
                return pageModels.size
            }

            override fun getPageTitle(position: Int): CharSequence? {
                return getString(pageModels[position].titleRes)
            }
        }
        tabLayout.setupWithViewPager(pager)
    }

}